package com.tchepannou.limbe.model;

import java.io.Serializable;

/**
 *
 * @author herve
 */
public abstract class Model
    implements Serializable
{
    //-- Abstract methods
    public abstract Serializable getId ();


    //-- Callback methods
    public void onSave ()
    {

    }

    public void onLoad()
    {

    }

    //-- Object overrides
    @Override
    public boolean equals (Object o)
    {
        if (o != null && getClass () == o.getClass ())
        {
            Serializable id = getId ();
            if (id != null && o instanceof Model)
            {
                Serializable xid = ((Model)o).getId ();
                return id.equals (xid);
            }
            return super.equals(o);
        }
        return false;
    }

    @Override
    public int hashCode ()
    {
        Serializable id = getId ();
        return id != null ? id.hashCode () : super.hashCode();
    }

    @Override
    public String toString ()
    {
        return getClass ().getSimpleName () + "{" + getId () + "}";
    }    
}
